import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;

/**
 * I am the visual representation of Thomas life.
 * @author Hugo Armando Rodríguez Flores
 * @version May 26th 2013
 */
public class Lifebar extends Actor
{
    private ArrayList<GreenfootImage> lifeBar;
    
    /**
     * This constructor store all the images corresponding to the lifeBar
     */
    public Lifebar ()
    {
        String tempString=new String(); //Temporal string that gets the name of the image file.
        lifeBar=new ArrayList<GreenfootImage>();
        for (int i=0; i<11; i++)
        {
            tempString="lifebar"+(i+1)+".png"; //this concatenates a defined name.
            lifeBar.add(new GreenfootImage(tempString));
        }
    }
    
    /**
     * This changes the image in relation with Thomas life
     * @param life is an integer that tell the current life Thomas has
     */
    public void changeImage(int life)
    {
        if (life>90 && life<=100)  this.setImage(lifeBar.get(0));
        if (life>80 && life<=90)    this.setImage(lifeBar.get(1));
        if (life>70 && life<=80)    this.setImage(lifeBar.get(2));
        if (life>60 && life<=70)    this.setImage(lifeBar.get(3));
        if (life>50 && life<=60)    this.setImage(lifeBar.get(4));
        if (life>40 && life<=50)    this.setImage(lifeBar.get(5));
        if (life>30 && life<=40)    this.setImage(lifeBar.get(6));
        if (life>20 && life<=30)    this.setImage(lifeBar.get(7));
        if (life>10 && life<=20)    this.setImage(lifeBar.get(8));
        if (life>0 && life<=10)   this.setImage(lifeBar.get(9));
        if (life<=0)    this.setImage(lifeBar.get(10));
    }
}
